/*   1:    */ package org.jetbrains.jps.model.library.impl;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.*;
import org.jetbrains.jps.model.ex.JpsElementCollectionRole;
import org.jetbrains.jps.model.ex.JpsNamedCompositeElementBase;
import org.jetbrains.jps.model.impl.JpsElementCollectionImpl;
import org.jetbrains.jps.model.library.*;
import org.jetbrains.jps.model.library.JpsLibraryRoot.InclusionOptions;
import org.jetbrains.jps.util.JpsPathUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */
/*  24:    */
/*  25:    */
/*  26:    */
/*  27:    */
/*  28:    */
/*  29:    */
/*  30:    */ 
/*  31:    */ public class JpsLibraryImpl<P extends JpsElement>
/*  32:    */   extends JpsNamedCompositeElementBase<JpsLibraryImpl<P>>
/*  33:    */   implements JpsTypedLibrary<P>
/*  34:    */ {
/*  35:    */   private final JpsLibraryType<P> a;
/*  36:    */   
/*  37:    */   public JpsLibraryImpl(@NotNull String paramString, @NotNull JpsLibraryType<P> paramJpsLibraryType, @NotNull P paramP)
/*  38:    */   {
/*  39: 40 */     super(paramString);
/*  40: 41 */     this.a = paramJpsLibraryType;
/*  41: 42 */     this.myContainer.setChild(this.a.getPropertiesRole(), paramP);
/*  42:    */   }
/*  43:    */   
/*  44:    */   private JpsLibraryImpl(@NotNull JpsLibraryImpl<P> paramJpsLibraryImpl)
/*  45:    */   {
/*  46: 46 */     super(paramJpsLibraryImpl);
/*  47: 47 */     this.a = paramJpsLibraryImpl.a;
/*  48:    */   }
/*  49:    */   
/*  50:    */   @NotNull
/*  51:    */   public JpsLibraryType<P> getType()
/*  52:    */   {
/*  53: 53 */     JpsLibraryType tmp4_1 = this.a;
/*  54: 53 */     if (tmp4_1 == null) {
/*  55: 53 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/jps/model/library/impl/JpsLibraryImpl", "getType" }));
/*  56:    */     }
/*  57: 53 */     return tmp4_1;
/*  58:    */   }
/*  59:    */   
/*  60:    */   @Nullable
/*  61:    */   public <P extends JpsElement> JpsTypedLibrary<P> asTyped(@NotNull JpsLibraryType<P> paramJpsLibraryType)
/*  62:    */   {
/*  63: 60 */     if (paramJpsLibraryType == null) {
/*  64: 60 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/library/impl/JpsLibraryImpl", "asTyped" }));
/*  65:    */     }
/*  66: 60 */     return this.a.equals(paramJpsLibraryType) ? this : null;
/*  67:    */   }
/*  68:    */   
/*  69:    */   @NotNull
/*  70:    */   public P getProperties()
/*  71:    */   {
/*  72: 66 */     JpsElement tmp16_13 = this.myContainer.getChild(this.a.getPropertiesRole());
/*  73: 66 */     if (tmp16_13 == null) {
/*  74: 66 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/jps/model/library/impl/JpsLibraryImpl", "getProperties" }));
/*  75:    */     }
/*  76: 66 */     return tmp16_13;
/*  77:    */   }
/*  78:    */   
/*  79:    */   @NotNull
/*  80:    */   public List<JpsLibraryRoot> getRoots(@NotNull JpsOrderRootType paramJpsOrderRootType)
/*  81:    */   {
/*  82: 72 */     if (paramJpsOrderRootType == null) {
/*  83: 72 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/library/impl/JpsLibraryImpl", "getRoots" }));
/*  84:    */     }
/*  85: 72 */     JpsElementCollection localJpsElementCollection = (JpsElementCollection)this.myContainer.getChild(a(paramJpsOrderRootType)); List 
/*  86: 73 */       tmp71_68 = (localJpsElementCollection != null ? localJpsElementCollection.getElements() : Collections.emptyList());
/*  87: 73 */     if (tmp71_68 == null) {
/*  88: 73 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/jps/model/library/impl/JpsLibraryImpl", "getRoots" }));
/*  89:    */     }
/*  90: 73 */     return tmp71_68;
/*  91:    */   }
/*  92:    */   
/*  93:    */   public void addRoot(@NotNull String paramString, @NotNull JpsOrderRootType paramJpsOrderRootType)
/*  94:    */   {
/*  95: 78 */     if (paramString == null) {
/*  96: 78 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/library/impl/JpsLibraryImpl", "addRoot" }));
/*  97:    */     }
/*  98: 78 */     if (paramJpsOrderRootType == null) {
/*  99: 78 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/jps/model/library/impl/JpsLibraryImpl", "addRoot" }));
/* 100:    */     }
/* 101: 78 */     addRoot(paramString, paramJpsOrderRootType, JpsLibraryRoot.InclusionOptions.ROOT_ITSELF);
/* 102:    */   }
/* 103:    */   
/* 104:    */   public void addRoot(@NotNull File paramFile, @NotNull JpsOrderRootType paramJpsOrderRootType)
/* 105:    */   {
/* 106: 83 */     if (paramFile == null) {
/* 107: 83 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/library/impl/JpsLibraryImpl", "addRoot" }));
/* 108:    */     }
/* 109: 83 */     if (paramJpsOrderRootType == null) {
/* 110: 83 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/jps/model/library/impl/JpsLibraryImpl", "addRoot" }));
/* 111:    */     }
/* 112: 83 */     addRoot(JpsPathUtil.getLibraryRootUrl(paramFile), paramJpsOrderRootType);
/* 113:    */   }
/* 114:    */   
/* 115:    */   public void addRoot(@NotNull String paramString, @NotNull JpsOrderRootType paramJpsOrderRootType, @NotNull JpsLibraryRoot.InclusionOptions paramInclusionOptions)
/* 116:    */   {
/* 117: 89 */     if (paramString == null) {
/* 118: 89 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/library/impl/JpsLibraryImpl", "addRoot" }));
/* 119:    */     }
/* 120: 89 */     if (paramJpsOrderRootType == null) {
/* 121: 89 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/jps/model/library/impl/JpsLibraryImpl", "addRoot" }));
/* 122:    */     }
/* 123: 89 */     if (paramInclusionOptions == null) {
/* 124: 89 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "2", "org/jetbrains/jps/model/library/impl/JpsLibraryImpl", "addRoot" }));
/* 125:    */     }
/* 126: 89 */     ((JpsElementCollection)this.myContainer.getOrSetChild(a(paramJpsOrderRootType))).addChild(new JpsLibraryRootImpl(paramString, paramJpsOrderRootType, paramInclusionOptions));
/* 127:    */   }
/* 128:    */   
/* 129:    */   public void removeUrl(@NotNull String paramString, @NotNull JpsOrderRootType paramJpsOrderRootType)
/* 130:    */   {
/* 131: 94 */     if (paramString == null) {
/* 132: 94 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/library/impl/JpsLibraryImpl", "removeUrl" }));
/* 133:    */     }
/* 134: 94 */     if (paramJpsOrderRootType == null) {
/* 135: 94 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/jps/model/library/impl/JpsLibraryImpl", "removeUrl" }));
/* 136:    */     }
/* 137: 94 */     JpsElementCollection localJpsElementCollection = (JpsElementCollection)this.myContainer.getChild(a(paramJpsOrderRootType));
/* 138: 95 */     if (localJpsElementCollection != null) {
/* 139: 96 */       for (JpsLibraryRoot localJpsLibraryRoot : localJpsElementCollection.getElements()) {
/* 140: 97 */         if ((localJpsLibraryRoot.getUrl().equals(paramString)) && (localJpsLibraryRoot.getRootType().equals(paramJpsOrderRootType)))
/* 141:    */         {
/* 142: 98 */           localJpsElementCollection.removeChild(localJpsLibraryRoot);
/* 143: 99 */           break;
/* 144:    */         }
/* 145:    */       }
/* 146:    */     }
/* 147:    */   }
/* 148:    */   
/* 149:    */   private static JpsElementCollectionRole<JpsLibraryRoot> a(JpsOrderRootType paramJpsOrderRootType)
/* 150:    */   {
/* 151:106 */     return JpsElementCollectionRole.create(new JpsLibraryRootRole(paramJpsOrderRootType));
/* 152:    */   }
/* 153:    */   
/* 154:    */   public void delete()
/* 155:    */   {
/* 156:111 */     getParent().removeChild(this);
/* 157:    */   }
/* 158:    */   
/* 159:    */   public JpsElementCollectionImpl<JpsLibrary> getParent()
/* 160:    */   {
/* 161:116 */     return (JpsElementCollectionImpl)this.myParent;
/* 162:    */   }
/* 163:    */   
/* 164:    */   @NotNull
/* 165:    */   public JpsLibraryImpl<P> createCopy()
/* 166:    */   {
/* 167:122 */     void tmp8_5 = new JpsLibraryImpl(this);
/* 168:122 */     if (tmp8_5 == null) {
/* 169:122 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/jps/model/library/impl/JpsLibraryImpl", "createCopy" }));
/* 170:    */     }
/* 171:122 */     return tmp8_5;
/* 172:    */   }
/* 173:    */   
/* 174:    */   @NotNull
/* 175:    */   public JpsLibraryReference createReference()
/* 176:    */   {
/* 177:128 */     void tmp15_12 = new JpsLibraryReferenceImpl(getName(), a());
/* 178:128 */     if (tmp15_12 == null) {
/* 179:128 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/jps/model/library/impl/JpsLibraryImpl", "createReference" }));
/* 180:    */     }
/* 181:128 */     return tmp15_12;
/* 182:    */   }
/* 183:    */   
/* 184:    */   private JpsElementReference<JpsCompositeElement> a()
/* 185:    */   {
/* 186:133 */     return ((JpsReferenceableElement)getParent().getParent()).createReference();
/* 187:    */   }
/* 188:    */   
/* 189:    */   public List<File> getFiles(JpsOrderRootType paramJpsOrderRootType)
/* 190:    */   {
/* 191:138 */     List localList = getRootUrls(paramJpsOrderRootType);
/* 192:139 */     ArrayList localArrayList = new ArrayList(localList.size());
/* 193:140 */     for (String str : localList) {
/* 194:141 */       localArrayList.add(JpsPathUtil.urlToFile(str));
/* 195:    */     }
/* 196:143 */     return localArrayList;
/* 197:    */   }
/* 198:    */   
/* 199:    */   public List<String> getRootUrls(JpsOrderRootType paramJpsOrderRootType)
/* 200:    */   {
/* 201:148 */     ArrayList localArrayList = new ArrayList();
/* 202:149 */     for (JpsLibraryRoot localJpsLibraryRoot : getRoots(paramJpsOrderRootType)) {
/* 203:150 */       switch (1.$SwitchMap$org$jetbrains$jps$model$library$JpsLibraryRoot$InclusionOptions[localJpsLibraryRoot.getInclusionOptions().ordinal()])
/* 204:    */       {
/* 205:    */       case 1: 
/* 206:152 */         localArrayList.add(localJpsLibraryRoot.getUrl());
/* 207:153 */         break;
/* 208:    */       case 2: 
/* 209:155 */         a(JpsPathUtil.urlToFile(localJpsLibraryRoot.getUrl()), false, localArrayList);
/* 210:156 */         break;
/* 211:    */       case 3: 
/* 212:158 */         a(JpsPathUtil.urlToFile(localJpsLibraryRoot.getUrl()), true, localArrayList);
/* 213:    */       }
/* 214:    */     }
/* 215:162 */     return localArrayList;
/* 216:    */   }
/* 217:    */   
/* 218:165 */   private static final Set<String> b = ContainerUtil.newTroveSet(FileUtil.PATH_HASHING_STRATEGY, new String[] { "jar", "zip", "swc", "ane" });
/* 219:    */   
/* 220:    */   private static void a(File paramFile, boolean paramBoolean, List<String> paramList)
/* 221:    */   {
/* 222:168 */     File[] arrayOfFile1 = paramFile.listFiles();
/* 223:169 */     if (arrayOfFile1 != null) {
/* 224:170 */       for (File localFile : arrayOfFile1)
/* 225:    */       {
/* 226:171 */         String str = FileUtilRt.getExtension(localFile.getName());
/* 227:172 */         if (localFile.isDirectory())
/* 228:    */         {
/* 229:173 */           if (paramBoolean) {
/* 230:174 */             a(localFile, paramBoolean, paramList);
/* 231:    */           }
/* 232:    */         }
/* 233:178 */         else if (b.contains(str)) {
/* 234:179 */           paramList.add(JpsPathUtil.getLibraryRootUrl(localFile));
/* 235:    */         }
/* 236:    */       }
/* 237:    */     }
/* 238:    */   }
/* 239:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.jps.model.library.impl.JpsLibraryImpl

 * JD-Core Version:    0.7.0.1

 */